{template '_header'}

<div class="page-heading">

    <h2>提现申请信息
        <small>申请单号: {$item['applyno']}</small>
        <small>商家信息: {$item['realname']} {$item['mobile']}</small>
    </h2>
</div>
<div class="step-region" >
    <ul class="ui-step ui-step-4" >
        <li {if $item['status']>=1}class="ui-step-done"{/if}>
        <div class="ui-step-title" >申请中</div>
        <div class="ui-step-number" >1</div>
        <div class="ui-step-meta" >{if 1<=$item['status']}{php echo date('Y-m-d',$item['applytime'])}<br/>{php echo date('H:i:s',$item['applytime'])}{/if}</div>
        </li>
        <li  {if $item['status']>=2}class="ui-step-done"{/if}>
        <div class="ui-step-title">商家审核</div>
        <div class="ui-step-number">2</div>
        <div class="ui-step-meta">{if 2<=$item['status']}{php echo date('Y-m-d',$item['checktime'])}<br/>{php echo date('H:i:s',$item['checktime'])}{/if}</div>
        </li>
        <li {if $item['status']>=3}class="ui-step-done"{/if}>
        <div class="ui-step-title">商家打款</div>
        <div class="ui-step-number" >3</div>
        <div class="ui-step-meta" >{if 3<=$item['status']}{php echo date('Y-m-d',$item['paytime'])}<br/>{php echo date('H:i:s',$item['paytime'])}{/if}</div>
        </li>
        <li {if $item['status']==-1}class="ui-step-done"{/if}>
        <div class="ui-step-title">无效</div>
        <div class="ui-step-number" >!</div>
        <div class="ui-step-meta" >{if -1==$item['status']}{php echo date('Y-m-d',$item['invalidtime'])}<br/>{php echo date('H:i:s',$item['invalidtime'])}{/if}</div>
        </li>
    </ul>
</div>

{template 'merch/manage/apply/box'}

{template 'merch/manage/apply/applytype'}

<form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
    <input type="hidden" name="c" value="site"/>
    <input type="hidden" name="a" value="entry"/>
    <input type="hidden" name="m" value="ewei_shopv2"/>
    <input type="hidden" name="do" value="web"/>
    <input type="hidden" name="id" value="{$id}"/>
    <input type="hidden" name="status" value="{$status}"/>
    <input type="hidden" name="r" value="merch.check.detail"/>

    <div class="page-toolbar row m-b-sm m-t-sm">

        <div class="col-sm-7 pull-right">
            <div class="input-group">
                <input type="text" class="form-control input-sm" name="keyword" value="{$_GPC['keyword']}"
                       placeholder="订单编号"/>
             <span class="input-group-btn">

            <button class="btn btn-sm btn-primary" type="submit"> 搜索</button>
            {ifp 'merch.check.detail.export'}
            <button type="submit" name="export" value="1" class="btn btn-success btn-sm">导出</button>
            {/if}
            </span>
            </div>
        </div>
    </div>

</form>

{template 'merch/manage/apply/table'}

<div class="form-group" style="margin-top:20px;">
    <div class="col-sm-12" style="text-align: right;">

            {if $item['status']==1}
                {ifp 'merch.check.confirm'}
                    <input type="button" id="btnconfirm" value="通过申请" class="btn btn-success"/>
                {/if}

                {ifp 'merch.check.refuse'}
                 <input type="button" id="btnnoconfirm" value="拒绝所有申请" class="btn btn-warning"/>
                {/if}
            {/if}


        {ifp 'merch.check.pay'}
            {if $item['status']==2}


                <div class="page-toolbar row m-b-sm m-t-sm">
                    <div class="col-sm-7 pull-right" style="width: 320px;">
                        <div class="input-group">
                            <input type="text" class="form-control input-sm" id="finalprice" name="finalprice" value="{$item['passrealpricerate']}" placeholder="打款金额"/>
                            <span class="input-group-btn">
                             {if $item['applytype']==0}
                            <button class="btn btn-sm btn-danger" id="btnpay" type="button" style="margin-left: 20px;"> 确认打款</button>
                            {/if}
                            <button class="btn btn-sm btn-warning" id="btnpayhand" type="button" style="margin-left: 20px;">手动处理</button>
                            </span>
                        </div>
                    </div>
                </div>


            {/if}
        {/if}


    </div>
</div>

<script>
    window.partners = [];
    window.current = 0;

    $(function () {

        $('.checkall').click(function () {
            var checked = $(this).prop('checked');
            $('.checkitem').prop('checked', checked);
        });

        $('#btnnoconfirm').click(function () {
            tip.confirm('确认要拒绝所有申请？',function(){
                confirm(-1);
            });
        });

        $('#btnconfirm').click(function () {
            if ($('.checkitem:checked').length<=0) {
                tip.msgbox.err('请选择通过申请的订单!');
                return;
            }

            $('.checkitem:checked').each(function(){
                window.partners.push( $(this).val() );
            });

            tip.confirm('通过申请后无法进行修改，确认吗？',function(){
                confirm(1);
            });
        });

        $('#btnpay').click(function () {
            if ($('#finalprice').isEmpty()) {
                tip.msgbox.err('请输入打款金额!');
                return;
            }
            var finalprice = $('#finalprice').val();
            var msg = '确认要打款' + finalprice + '元吗？';

            tip.confirm(msg,function(){
                $('#btnpay').button('loading');

                $.ajax({
                    url: "{php echo webUrl('merch/check/merchpay')}",
                    type: 'post',
                    dataType: 'json',
                    data: {
                        id: "{$item['id']}", 'finalprice': finalprice, 'handpay': 0
                    },
                    success: function (ret) {
                        $('#btnpay').button('reset');

                        var result = ret.result;
                        if (ret.status != 1) {
                            tip.msgbox.err(result.message);
                            return;
                        }
                        location.href = biz.url("merch.check.status{$status}");
                    }
                });
            });
        });

        $('#btnpayhand').click(function () {
            if ($('#finalprice').isEmpty()) {
                tip.msgbox.err('请输入打款金额!');
                return;
            }
            var applytype = $('#applytype').val();
            var msg = '手动处理 , 系统不进行任何打款操作!<br/>请确认你已通过线下方式为商户打款!!!<br/>是否进行手动处理?';
            var finalprice = $('#finalprice').val();

            tip.confirm(msg,function(){
                $('#btnpayhand').button('loading');

                $.ajax({
                    url: "{php echo webUrl('merch/check/merchpay')}",
                    type: 'post',
                    dataType: 'json',
                    data: {
                        id: "{$item['id']}", 'finalprice': finalprice, 'handpay': 1
                    },
                    success: function (ret) {
                        $('#btnpayhand').button('reset');

                        var result = ret.result;
                        if (ret.status != 1) {
                            tip.msgbox.err(result.message);
                            return;
                        }
                        location.href = biz.url("merch.check.status{$status}");
                    }
                });
            });
        });
    });

    function confirm(type){
        if (type == 1) {
            $('#btnconfirm').button('loading');
        } else {
            $('#btnnoconfirm').button('loading');
        }

        $.ajax({
            url: "{php echo webUrl('merch/check/confirm')}",
            type: 'post',
            dataType: 'json',
            data: {
                id: "{$item['id']}", 'bpid': window.partners, 'type': type
            },
            success: function (ret) {
                if (type == 1) {
                    $('#btnconfirm').button('reset');
                } else {
                    $('#btnnoconfirm').button('reset');
                }
                var result = ret.result;
                if (ret.status != 1) {
                    tip.msgbox.err(result.message);
                    return;
                }
                location.href = biz.url("merch.check.status{$status}");
            }
        });



    }

</script>

{template '_footer'}